/* GUI CONVERTED from rcsdpntc.p (converter v1.76) Sun Feb 24 20:08:38 2002 */
/* rcsdpntc.p - Release Management Customer Schedules                   */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                  */
/* All rights reserved worldwide.  This is an unpublished work.         */
/* $Revision: 1.7 $                                                        */
/*V8:ConvertMode=Maintenance                                            */
/* REVISION: 7.3    LAST MODIFIED: 01/05/93           BY: WUG *G462*    */
/* REVISION: 7.3    LAST MODIFIED: 08/10/93           BY: WUG *GE06*    */

/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane    */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan   */
/* REVISION: 8.6E     LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan   */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KP* myb          */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* $Revision: 1.7 $    BY: Anitha Gopal          DATE: 02/17/02  ECO: *N19G*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/
/* INTERPRETS SHIP/DELIVERY PATTERN CODE SUBROUTINE */
/* DISTRIBUTES QUANTITIES OF THE DATE ARRAY BASED ON RELATIVE HOURS PER DAY */

{mfdeclre.i}

/* INPUT PARAMETERS: */
define shared variable req_qty as decimal.
define shared variable resch_ct as integer.
define shared variable resch_dt as date extent 999 no-undo.
define shared variable shipto_calid as character.
define shared variable report_yn like mfc_logical label "Report" initial yes.

/* OUTPUT PARAMETERS: */
define shared variable resch_qty as decimal extent 999 no-undo.
define shared variable working_hours as decimal extent 999 no-undo.


define variable work_sum as decimal.
define variable i as integer no-undo.
define variable total_hours as decimal.
define variable work_qty as decimal.

find shop_cal
   where shop_site  = shipto_calid
   and   shop_wkctr = ""
   and   shop_mch   = "" no-lock no-error.

total_hours = 0.
if available shop_cal
then do:
   do i = 1 to resch_ct:
      {wccapday.i &date=resch_dt[i]  &caphrs=working_hours[i]}
      total_hours = total_hours + working_hours[i].
   end. /* DO i = 1 TO resch_ct */
end. /* IF AVAILABLE shop_cal */

if total_hours = 0
then do:
   {gprun.i ""rcsdpnta.p""}
/*GUI*/ if global-beam-me-up then undo, leave.

end. /* IF total_hours = 0 */
else do:
   work_qty = 0.
   do i = 1 to resch_ct:
      assign
         resch_qty[i] = round(req_qty * (working_hours[i] / total_hours),0)
         work_qty = work_qty + resch_qty[i].
   end. /* DO i = 1 TO resch_ct */

   /* IF THE NEW SUM IS GREATER FROM THE ORIGINAL REQ QTY,
   GO THRU AND ADJUST EACH QTY BY 1 UNTIL WE ARE EQUAL */
   if work_qty > req_qty
   then do:
      i = resch_ct.
      do while work_qty > req_qty:
         if resch_qty[i] >= 1
         then
            assign
               resch_qty[i] = resch_qty[i] - 1
               work_qty = work_qty - 1.

         i = i - 1.
         if i = 0
         then
            i = resch_ct.
      end. /* DO WHILE work_qty > req_qty */
   end. /* IF work_qty > req_qty */
   else
   if work_qty < req_qty
   then do:
      i = 1.
      do while work_qty < req_qty:

         assign
            resch_qty[i] = resch_qty[i] + 1
            work_qty = work_qty + 1
            i = i + 1.

         if i > resch_ct
         then
            i = 1.
      end. /* DO WHILE work_qty < req_qty */
   end. /* IF work_qty < req_qty */
end. /* ELSE DO */
